<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/X-admin/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body >

<script type="text/javascript">
    //设置日期选择框
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#start', //指定元素
            type: 'date', //指定元素
            format:"y:MM:dd",//指定元素
            value: new Date(),
            max :0
        });

        var laydate1 = layui.laydate;
        laydate1.render({
            elem: '#end', //指定元素
            type: 'date',
            format:"y:MM:dd",//指定元素
            value: new Date(),
            max :0
        });
    });

</script>


<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <div class="layui-form layui-col-space5">
                        <div class="layui-input-inline layui-show-xs-block">
                            <input class="layui-input" placeholder="开始日" name="start" id="start"></div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <input class="layui-input" placeholder="截止日" name="end" id="end"></div>


                        <div class="layui-input-inline layui-show-xs-block">
                            <input type="text" id="QQ" name="QQ" placeholder="请输入qq号" autocomplete="off" class="layui-input"></div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <button class="layui-btn"  onclick="frash()">
                                <i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </div>
                    <button type="button" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-normal "  onclick="frash() " style="float:right">
                        <i class="layui-icon">&#xe666;</i>
                    </button>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()">
                        <i class="layui-icon">&#xe640;</i>批量删除</button>
                    <button class="layui-btn" onclick="member_add()">
                        <i class="layui-icon">&#xe654;</i>出刀</button></div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form" lay-filter="knife" id="knifeTable">
                        <thead>
                        <tr>
                            <th lay-fileNames="{ sort:true}">序号</th>
                            <th>出刀人qq</th>
                            <th>昵称</th>
                            <th>周目</th>
                            <th>王位</th>
                            <th>伤害</th>
                            <th>出刀时间</th>
                            <th>不为补时刀</th>
                            <th th:if="${Power}>1">操作</th></tr>
                        </thead>
                        <tbody id="knife">

                        </tbody>
                    </table>
                </div>

            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    function frash() {
        //正在出刀
        var xhr=new XMLHttpRequest();
        xhr.open('get','/Fight/GroupKnifeList?start='+document.getElementById("start").value+'&end='+document.getElementById("end").value+"&QQ="+document.getElementById("QQ").value);
        xhr.send();
        xhr.onload=function (){
            var html='';
            var date=JSON.parse(xhr.responseText);
            if([[${Power}]]>1){
                for(var i=0;i<date.length;i++){
                    html+="<tr>"
                        +'<td>'+date[i].id+'</td>'+'<td>'+date[i].knifeQQ+'</td>'
                        +'<td>'+date[i].name+'</td>'
                        +'<td>'+(date[i].no-date[i].no%10)/10+'</td>'
                        +'<td>'+date[i].no%10+'</td>'
                        +'<td>'+date[i].hurt+'</td>'
                        +'<td>'+date[i].date+'</td>'
                        +'<td>'+date[i].complete+'</td>'
                        +'<td   class="td-manage">\n' +
                        '<a title="查看" onclick=member_edi('+date[i].id+') href="javascript:;">\n' +
                        '<i class="layui-icon">&#xe63c;</i></a>\n' +
                        '<a title="删除" onclick="member_del(this,'+date[i].id+')" href="javascript:;">\n' +
                        '<i class="layui-icon">&#xe640;</i></a>\n' +
                        '</td>'
                        +'</tr>'
                }
            }else {
                for(var i=0;i<date.length;i++) {
                    html += "<tr>"
                        + '<td>' + date[i].id + '</td>' + '<td>' + date[i].knifeQQ + '</td>'
                        + '<td>' + date[i].name + '</td>'
                        + '<td>' + (date[i].no - date[i].no % 10) / 10 + '</td>'
                        + '<td>' + date[i].no % 10 + '</td>'
                        + '<td>' + date[i].hurt + '</td>'
                        + '<td>' + date[i].date + '</td>'
                        + '<td>' + date[i].complete + '</td>'
                        + '</tr>'
                }
            }

            $("#knife").html(html);
        }

    }

    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？',
            function(index) {
                //发异步删除数据
                console.log()
                var xhr1=new XMLHttpRequest();
                xhr1.open('post','/Fight/delete/'+id);
                xhr1.send();
                xhr1.onload=function (){
                    var date=JSON.parse(xhr1.responseText);
                    if(date){
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!', {
                            icon: 1,
                            time: 1000
                        });
                    }else {
                        layer.msg('删除失败!', {
                            icon: 1,
                            time: 1000
                        });
                    }
                }
            });
    }

    /*用户-添加*/
    function member_add(){
            //iframe层
        var w=($(window).width()*0.9);var h=($(window).height() - 50);
            parent.layer.open({
                type: 2,
                title: '出刀',
                shade: 0.8,
                area: [w+'px', h +'px'],
                fix: false, //不固定
                maxmin: true,
                shadeClose: true,
                content: ['/Fight/add', 'yes'] //iframe的url，yes是否有滚动条
                ,btn: ['提交', '取消']
                ,yes: function(index, layero){
                    //按钮【按钮一】的回调
                    var form = $(layero).find("iframe")[0].contentWindow.document;
                    var loop;//这个名字是直接复制下面的，所以和真实的控件名字有一点点点不同
                    var remnant;
                    var serial;
                    var StartTime;
                    var EndTime;
                    if([[${Power}]]<2){
                        loop=form.getElementById('userQQ').value;
                        remnant=form.getElementById('hurt').value;
                        serial=form.getElementById('loop').value;
                        StartTime=form.getElementById('serial').value;
                        EndTime=form.getElementById('time').value;
                    }else {
                        loop=form.getElementById('userQQ1').value;
                        remnant=form.getElementById('hurt').value;
                        serial=form.getElementById('loop1').value;
                        StartTime=form.getElementById('serial1').value;
                        EndTime=form.getElementById('time1').value;
                    }

                    var xhr3=new XMLHttpRequest();
                    xhr3.open('post','/Fight/add1?userQQ='+loop+"&hurt="+remnant+"&loop="+serial+"&serial="+StartTime+"&time="+EndTime);
                    xhr3.send();
                    xhr3.onload=function (){
                        if(JSON.parse(xhr3.responseText)){
                            layer.msg('出刀成功');
                            frash();
                        }else {
                            layer.msg('出刀失败,\n错误原因：我不知道')
                        }
                    }
                    parent.layer.close(index)
                }
            });
    }

    function member_edi(i){
        //iframe层
        var w=($(window).width()*0.9);var h=($(window).height() - 50);
        parent.layer.open({
            type: 2,
            title: '出刀',
            shade: 0.8,
            area: [w+'px', h +'px'],
            fix: false, //不固定
            maxmin: true,
            shadeClose: true,
            content: ['/Fight/edit?id='+i, 'yes'] //iframe的url，yes是否有滚动条
            ,btn: ['提交', '取消']
            ,yes: function(index, layero){
                //按钮【按钮一】的回调
                var form = $(layero).find("iframe")[0].contentWindow.document;
                var id=form.getElementById('id').value;//这个名字是直接复制下面的，所以和真实的控件名字有一点点点不同
                var userQQ=form.getElementById('userQQ').value;
                var hurt=form.getElementById('hurt').value;
                var loop=form.getElementById('loop').value;
                var serial=form.getElementById('serial').value;
                var time=form.getElementById('time').value;
                console.log('/Fight/edit1?id='+id+"&userQQ="+userQQ+"&hurt="+hurt+"&loop="+loop+"&serial="+serial+"&time="+time)
                var xhr3=new XMLHttpRequest();
                xhr3.open('post','/Fight/edit1?id='+id+"&userQQ="+userQQ+"&hurt="+hurt+"&loop="+loop+"&serial="+serial+"&time="+time);
                xhr3.send();
                xhr3.onload=function (){
                    if(JSON.parse(xhr3.responseText)){
                        layer.msg('修改成功');
                        frash();
                    }else {
                        layer.msg('修改失败')
                    }
                }
                parent.layer.close(index)
            }
        });
    }
    window.onload=frash;//加载数据



</script>

</body>
</html>